package com.aios.dao;

import com.aios.entity.Controller;
import com.aios.entity.ControllerExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

public interface ControllerMapper {

	int countByExample(ControllerExample example);

	int deleteByExample(ControllerExample example);

	int deleteByPrimaryKey(String id);

	int insert(Controller record);

	int insertSelective(Controller record);

	List<Controller> selectByExample(ControllerExample example);

	Controller selectByPrimaryKey(String id);

	int updateByExampleSelective(@Param("record") Controller record,
			@Param("example") ControllerExample example);

	int updateByExample(@Param("record") Controller record,
			@Param("example") ControllerExample example);

	int updateByPrimaryKeySelective(Controller record);

	int updateByPrimaryKey(Controller record);

	@Select("SELECT c.* FROM controller as c,system_user_has_controller as suhc WHERE c.ID=suhc.CONTROLLER_ID AND suhc.SYSTEM_USER_ID=#{id}")
	@ResultMap("MiniResultMap")
	List<Controller> findControllerByUserID(@Param("id") String id);

	@Select("SELECT * FROM controller WHERE STATUS = #{status} ORDER BY SORT_ORDER")
	@ResultMap(value = "MiniResultMap")
	List<Controller> findAllByStatus(int status);

	@Select("SELECT * FROM controller WHERE NAME = #{name}")
	@ResultMap(value = "MiniResultMap")
	List<Controller> findByName(@Param("name") String name);

	@Select("SELECT c.NAME FROM controller c,system_user_has_controller suhc WHERE c.ID=suhc.CONTROLLER_ID  AND c.ID != #{id} AND c.NAME = #{name} AND suhc.SYSTEM_USER_ID = #{userId}")
	@ResultMap(value = "MiniResultMap")
	List<Controller> findByNameNotWithId(@Param("id") String id, @Param("name") String name,
			@Param("userId") String userId);

	@Select("SELECT controller.* FROM controller, system_user_has_controller " +
			"WHERE system_user_has_controller.CONTROLLER_ID = controller.ID AND " +
			"system_user_has_controller.SYSTEM_USER_ID = #{id}")
	@ResultMap(value = "MiniResultMap")
	List<Controller> findByUserId(@Param("userId") String userid);

}